﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_MailGetCompleteInfo]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_MailGetCompleteInfo];
GO
-------------------------------------------------------------------------------
-- sproc_MailGetBriefInfo
-------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[sproc_MailGetCompleteInfo]
(
    @MailID            nvarchar(100)
)
AS
    IF(len(@MailID)<8)
      BEGIN
         UPDATE TabMailList SET MailReadFlag=1 WHERE MailId=@MailID    
         SELECT MailID,(SELECT RealName FROM UDS_Staff a where a.Staff_Name=MailSender) as MailSender,(SELECT RealName FROM UDS_Staff a where a.Staff_Name=MailReceiver)  as MailReceiver,MailSendDate,MailSubject,MailBccToAddr,MailCcToAddr,MailBody,MailReadFlag,MailReceiverStr,MailSender,(select ClassName from uds_class b where b.classid=TabMailList.classid)  as classname
         FROM TabMailList
         WHERE    MailID = @MailID
     END
   ELSE
      declare @sql nvarchar(4000)   
     select @sql = '  SELECT Subject as MailSubject,TextContent as MailBody ,FromName as MailSender,Ccto as MailCcToAddr,Bccto as MailBccToAddr,SendDate as MailSendDate,''''as MailReceiverStr,''外部邮件'' as classname
    FROM TabExtMailList
    WHERE MailID ='''+ @MailID + ''''
  -- print @sql
   exec (@sql)